/*
 * $Id: SystemLoadParamDAO.java,v 1.5 2009/07/10 18:36:46 navdeep_mahajan Exp $
 * 
 * Copyright (C) 2006 General Electric Company. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of the General
 * Electric Company (GE). You shall not disclose this software and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with GE.
 * 
 * GE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. GE SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */
package com.ge.healthcare.autosc.common.database.dao;

import java.util.Iterator;
import java.util.List;

import com.ge.healthcare.autosc.common.ASCLogger;
import com.ge.healthcare.autosc.common.ASCUtil;
import com.ge.healthcare.autosc.common.database.pojo.CfgSystemLoadParam;
import com.ge.healthcare.autosc.common.load.CategoryQueue;
import com.ge.healthcare.autosc.common.load.IResourceQueue;
import com.ge.healthcare.autosc.common.load.PortMasterQueue;
import com.ge.healthcare.autosc.common.load.ServiceCenterQueue;

/**
 * @author 212042764
 * 
 */
public class SystemLoadParamDAO extends BaseDAO implements ISystemLoadParamDAO {

	/**
	 * Eclipse generated
	 */
	private static final long serialVersionUID = 4228065634089112483L;

	public SystemLoadParamDAO() {
		super(CfgSystemLoadParam.TABLE_NAME);
	}

	public IResourceQueue getLoadParamByType(String type) {
		return getLoadParamByType(type, 1);
	}

	public IResourceQueue getLoadParamByType(String type, int muliplier) {
		StringBuffer msg = new StringBuffer(
				"Load System Param Configuration for ");
		msg.append(type).append(" Multiplyer: ").append(muliplier);
		ASCLogger.debug(this.getClass(), "getLoadParamByType", msg);
		IResourceQueue queue = null;
		if (CfgSystemLoadParam.TYPE_CATIGORY.equalsIgnoreCase(type)) {
			queue = new CategoryQueue();
		} else if (CfgSystemLoadParam.TYPE_SVC_CENTER.equalsIgnoreCase(type)) {
			queue = new ServiceCenterQueue();
		} else if (CfgSystemLoadParam.TYPE_PORTMASTER.equalsIgnoreCase(type)) {
			queue = new PortMasterQueue();
		} else {
			msg.append(" Type has no known Resource Queue type associated");
			ASCLogger.error(this.getClass(), "getLoadParamByType", msg
					.toString());
			throw new RuntimeException(msg.toString());
		}

		List<?> rows = findByProperty(CfgSystemLoadParam.COL_TYPE, type);
		if (ASCUtil.isNullOrEmptyList(rows)) {
			return null;
		}
		for (Iterator<?> iterator = rows.iterator(); iterator.hasNext();) {
			CfgSystemLoadParam sysLP = (CfgSystemLoadParam) iterator.next();
			queue.addQueue(sysLP.getName(), sysLP
					.createResourceLoadType(muliplier));
		}
		ASCLogger.info(msg);
		return queue;
	}

	public void save(Object pojo) {
		super.save(pojo);
	}

	public void saveAlways(Object pojo) {
		super.save(pojo);
	}

	public void deleteByID(Object pojo) {
		super.deleteByID(pojo);
	}

	public void refresh(Object pojo) {
		super.refresh(pojo);
	}

}
